package com.sun.forumautotest.tests;

/**
 * @Author sun
 */

import com.sun.forumautotest.common.AutoTestUtil;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.io.IOException;

public class ForumRegister {

    WebDriver driver = AutoTestUtil.createDriverUtil();


    @Order(1)
    @ParameterizedTest
    @CsvSource({"zyt, 周诣涛, 123456, 123456"})
    void register(String username, String nickname, String password, String passwordRepeat) throws InterruptedException, IOException {
        driver.get("http://120.26.251.76:58080/sign-up.html");

        driver.findElement(By.cssSelector("#username")).sendKeys(username);
        driver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);
        driver.findElement(By.cssSelector("#password")).sendKeys(password);
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);

        // 点击同意用户协议
        driver.findElement(By.cssSelector("#policy")).click();
        // 点击注册
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(1000);
        AutoTestUtil.getScreenshotAs(getClass().getName() + "_" + AutoTestUtil.currentMethodName());

    }

    @Order(2)
    @ParameterizedTest
    @CsvSource({"zyt, 周诣涛, 123456, 123456"})
    void noRegister(String username, String nickname, String password, String passwordRepeat) throws InterruptedException, IOException {
        driver.get("http://120.26.251.76:58080/sign-up.html");

        driver.findElement(By.cssSelector("#username")).sendKeys(username);
        driver.findElement(By.cssSelector("#nickname")).sendKeys(nickname);
        driver.findElement(By.cssSelector("#password")).sendKeys(password);
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys(passwordRepeat);
        // 点击同意用户协议
        driver.findElement(By.cssSelector("#policy")).click();
        // 点击注册
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(1000);
        AutoTestUtil.getScreenshotAs(getClass().getName() + "_" + AutoTestUtil.currentMethodName());
    }


}
